#ifndef COMMANDER_H
#define COMMANDER_H

#include <QDebug>
#include <QFile>
#include <QList>
#include <QObject>
#include <QString>
#include <QVariant>

class Commander : public QObject {
    Q_OBJECT
public:
    Commander()
        : m_nSameCnt(0), m_nPos(999999999999)
    {
    }

    virtual ~Commander()
    {
    }

    /// @brief
    /// @param strCmdName: setI, repos
    /// @param cmd
    /// @param nParam
    /// @return
    int getCmd(const QString& strCmdName, quint8* cmd, int nParam = 0);
    int parseCmd(quint8* buff, quint8 bufLen);

signals:
    void sigJudge(const QByteArray& ba);

protected:
    void setCurrent(int n);  // unit: mA
    void setRepos();
    void spinBack45();
    void spin45();

    void CmdSetCurrent();
    void CmdSetRePose();
    void getCmd(quint8* buffIn, quint8 bufLen);
    void cal_CRC(unsigned char* strCRC, int dataLen);

    void judge(int nPos, int nI, int nV);

protected:
    quint8 m_buff[17];
    quint32 m_nParam;
    int m_current;
    int m_nSameCnt;
    int m_nPos;
};

#endif  // COMMANDER_H
